
<div class="well">
	<h2><?= $user->fullname ?></h2>
	<p><?= lang('post_created') ?>: <strong><?= number_format($total_content, 0, ',', '.') ?></strong></p>
	<div>
		<?= lang('statistic') ?> <strong><?= lang('month') ?> <?= $month ?>/<?= $year ?></strong>:

		<ul>
			<li>
				<?= lang('post_created') ?>: <strong><?= $total ?></strong>
			</li>
			<li>
				<?= lang('total_view_all') ?>: <strong><?= number_format($total_view_all, 0, ',', '.') ?></strong>
			</li>
			<li>
				<strong><?= lang('facebook_data_total') ?>:</strong>
				<ul>
					<li><span class="fb_share_count_all"></span> <?= lang('shares') ?></li>
					<li><span class="fb_like_count_all"></span> <?= lang('likes') ?></li>
					<li><span class="fb_comment_count_all"></span> <?= lang('comments') ?></li>
					<!-- <li><span class="total_count_all"></span> total_count</li>
					<li><span class="click_count_all"></span> clicks</li>
					-->
					<li><span class="fb_commentsbox_count_all"></span> <?= lang('commentsbox') ?></li>
				</ul>
			</li>
		</ul>
	</div>
</div>
<?= formOpen(site_url('admin/dashboard/index'), 'post', 'id="adminForm" class="formAjax"') ?>
	<div class="table-responsive">
		<table class="table table-hover table-striped" id="tableList">
			<thead>
				<tr>
					<th width="1%" class="text-center nowrap"><?= filtersort($link, lang('id'), 'id', $direction, $ordering) ?></th>
					<th><?= filtersort($link, lang('title'), 'title', $direction, $ordering) ?></th>
					<th><?= filtersort($link, lang('category'), 'category_id', $direction, $ordering) ?></th>
					<th><?= filtersort($link, lang('created_time'), 'created_time', $direction, $ordering) ?></th>
					<th><?= filtersort($link, lang('source'), 'source_id', $direction, $ordering) ?></th>
					<th width="1%" class="text-center"><?= filtersort($link, lang('hit'), 'hit', $direction, $ordering) ?></th>
					<th width="10%"><?= lang('fb_data') ?></th>
					<th width="1%" class="text-center"><?= filtersort($link, lang('type'), 'type', $direction, $ordering) ?></th>
					<th width="1%" class="text-center"><?= filtersort($link, lang('hot'), 'hot', $direction, $ordering) ?></th>
					<th width="1%" class="text-center"><?= filtersort($link, lang('subject_hot'), 'subject_hot', $direction, $ordering) ?></th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="20" class="text-center">
					</td>
				</tr>
			</tfoot>
			<tbody class="sortable">
			<?php $order = array();
			foreach($items as $k=>$item):
				$item_link = siteUrl('post/detail/'.$item->id.'-'.$item->alias, $item->category_id);
			?>
				<tr data-id="<?= $item->id ?>">
					<td width="1%" class="text-center"><?= $item->id ?></td>
					<td><?= anchor('admin/post/form/'.$item->id, $item->title) ?></td>
					<td><?= $item->category->title ?></td>
					<td><?= mdate(lang('date_format_lc'), strtotime($item->created_time)) ?></td>
					<td><?= $item->source->title ?></td>
					<td width="1%" class="text-center"><?= $item->hit ?></td>
					<td>
						<p class="fb_data" data-link="<?= $item_link ?>">
							<span class="share_count"></span> shares<br />
							<span class="like_count"></span> likes<br />
							<span class="comment_count"></span> comments<br />
							<!-- <span class="total_count"></span> total_count<br />
							<span class="click_count"></span> clicks<br />
							-->
							<span class="commentsbox_count"></span> commentsboxs
						</p>
					</td>
					<td width="1%" class="text-center nowrap"><?= $type[$item->type] ?></td>
					<td width="1%" class="text-center">
						<a href="javascript:;" class="btn btn-default disabled btn-micro hasTip toggle linkAjax" title="<?= lang('toggle_to_hot') ?>"><i class="icon-<?php if(!$item->hot) echo 'un' ?>publish"></i></a>
					</td>
					<td width="1%" class="text-center">
						<a href="javascript:;" class="btn btn-default disabled btn-micro hasTip toggle linkAjax" title="<?= lang('toggle_to_subject_hot') ?>"><i class="icon-<?php if(!$item->subject_hot) echo 'un' ?>publish"></i></a>
					</td>
				</tr>
			<?php endforeach ?>
			</tbody>
		</table>
	</div>
<?= formClose() ?>


<script type="text/javascript">
	$(document).ready(function()
	{
		var share_count_all = 0, like_count_all = 0, comment_count_all = 0, commentsbox_count_all = 0;
		jQuery('.fb_data').each(function(idx, item)
		{
			var link = $(item).attr('data-link');
			$.get('http://api.facebook.com/restserver.php?method=links.getStats&urls='+link, function(xmlDoc)
			{
				var share_count = $(xmlDoc).find('share_count').text(),
				like_count = $(xmlDoc).find('like_count').text(),
				comment_count = $(xmlDoc).find('comment_count').text(),
				commentsbox_count = $(xmlDoc).find('commentsbox_count').text();

				$(item).children('.share_count').text(share_count);
				$(item).children('.like_count').text(like_count);
				$(item).children('.comment_count').text(comment_count);
				$(item).children('.commentsbox_count').text(commentsbox_count);

				share_count_all += Number(share_count);
				like_count_all += Number(like_count);
				comment_count_all += Number(comment_count);
				commentsbox_count_all += Number(commentsbox_count);
				$('.fb_share_count_all').text(share_count_all);
				$('.fb_like_count_all').text(like_count_all);
				$('.fb_comment_count_all').text(comment_count_all);
				$('.fb_commentsbox_count_all').text(commentsbox_count_all);
			});
		});
	});
</script>
